home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / resource / fonts / ps / prheader.ps < prev    next >
Encoding:
Text File  |  1997-07-08  |  5.0 KB  |  192 lines

  1. % File: prheader.ps
  2. % Copyright (c) 1988, Miguel Santana, miguel@imag.imag.fr
  3. % Based on header.ps file from a2ps package
  4.  
  5. % General macros.
  6. /xdef {exch def} bind def
  7. /getfont {exch findfont exch scalefont} bind def
  8.  
  9. % Page description variables and inch function are defined by a2ps program.
  10.  
  11. % Character size for differents fonts.
  12.    landscape
  13.    { /filenamefontsize 12 def }
  14.    { /filenamefontsize 16 def }
  15. ifelse
  16. /datefontsize filenamefontsize 0.8 mul def
  17. /headermargin filenamefontsize 0.25 mul def
  18. /bodymargin bodyfontsize 0.7 mul def
  19.  
  20. % Font assignment to differents kinds of "objects"
  21. /filenamefontname /Helvetica-Bold def
  22. /stdfilenamefont filenamefontname filenamefontsize getfont def
  23. /datefont /Helvetica datefontsize getfont def
  24. /bodyfont /Courier bodyfontsize getfont def
  25.  
  26. % Logical page attributs (a half of a real page or sheet).
  27. /pagewidth
  28.    bodyfont setfont (0) stringwidth pop columns mul bodymargin dup add add
  29.    def
  30. /pageheight
  31.    bodyfontsize lines mul bodymargin dup add add headersize add
  32.    def
  33.  
  34. % Coordinates for upper corner of a logical page and for sheet number.
  35. % Coordinates depend on format mode used.
  36. % In twinpage mode, coordinate x of upper corner is not the same for left
  37. % and right pages: upperx is an array of two elements, indexed by sheetside.
  38. /rightmargin margin 3 div def
  39. /leftmargin margin 2 mul 3 div def
  40. /topmargin margin twinpage {3} {2} ifelse div def
  41. landscape
  42. {  % Landscape format
  43.    /uppery rightmargin pageheight add bodymargin add def
  44.    /sheetnumbery sheetwidth leftmargin pageheight add datefontsize add sub def
  45.    twinpage
  46.    {  % Two logical pages
  47.       /upperx [ topmargin            % upperx for left page
  48.         dup pagewidth add        % upperx for right page
  49.           ] def
  50.       /sheetnumberx sheetheight topmargin sub def
  51.    }
  52.    {  /upperx [ topmargin dup ] def
  53.       /sheetnumberx sheetheight topmargin sub datefontsize sub def
  54.    }
  55.    ifelse
  56. }
  57. {  % Portrait format
  58.    /uppery topmargin pageheight add def
  59.    /upperx [ leftmargin dup ] def
  60.    /sheetnumberx sheetwidth rightmargin sub datefontsize sub def
  61.    /sheetnumbery
  62.      sheetheight 
  63.      topmargin pageheight add datefontsize add headermargin add
  64.       sub
  65.       def
  66.  
  67. }
  68. ifelse
  69.  
  70. % Strings used to make easy printing numbers
  71. /pnum 12 string def
  72. /empty 12 string def
  73.  
  74. % Other initializations.
  75. /datewidth date stringwidth pop def
  76. /filenameroom
  77.          pagewidth
  78.      filenamefontsize 4 mul datewidth add (Page 999) stringwidth pop add
  79.       sub
  80.    def
  81.  
  82.  
  83. % Function newfile: init file name and reset page number for each new file.
  84. /newfile
  85.     { cleanup
  86.       /filename xdef
  87.       /filenamewidth filename stringwidth pop def
  88.       /filenamefont
  89.      filenamewidth filenameroom gt
  90.      {
  91.            filenamefontname
  92.            filenamefontsize filenameroom mul filenamewidth div
  93.         getfont
  94.      }
  95.      {  stdfilenamefont }
  96.      ifelse
  97.      def
  98.     } bind def
  99.  
  100. % Function printpage: Print a physical page.
  101. /printpage
  102.     { /sheetside 0 def
  103.       twinpage noheader and
  104.       { sheetnumber }
  105.       if
  106.       showpage 
  107. %      pagesave restore
  108.       /sheet sheet 1 add def
  109.     } bind def
  110.  
  111. % Function cleanup: terminates printing, flushing last page if necessary.
  112. /cleanup
  113.     { twinpage sheetside 1 eq and
  114.          { printpage }
  115.       if
  116.     } bind def
  117.  
  118. %
  119. % Function startpage: prints page header and page border and initializes
  120. % printing of the file lines.
  121. /startpage
  122.     { sheetside 0 eq
  123.     { % /pagesave save def
  124.       landscape
  125.         { sheetwidth 0 inch translate    % new coordinates system origin
  126.           90 rotate                % landscape format
  127.         } if
  128.     } if
  129.       noheader not { printheader } if
  130.      upperx sheetside get  bodymargin  add
  131.         uppery
  132.         bodymargin bodyfontsize add  noheader {0} {headersize} ifelse  add
  133.      sub
  134.       moveto
  135.       bodyfont setfont
  136.     } bind def
  137.  
  138. % Function printheader: prints page header.
  139. /printheader
  140.     { upperx sheetside get  uppery headersize sub 1 add  moveto
  141.       datefont setfont
  142.       gsave
  143.         datefontsize headermargin rmoveto
  144.     date show                    % date/hour
  145.       grestore
  146.       gsave
  147.     pagenum pnum cvs pop
  148.        pagewidth (Page 999) stringwidth pop sub
  149.        headermargin
  150.     rmoveto
  151.         (Page ) show pnum show                % page number
  152.       grestore
  153.       empty pnum copy pop
  154.       gsave
  155.         filenamefont setfont
  156.           filenameroom filename stringwidth pop sub 2 div datewidth add
  157.           bodymargin 2 mul 
  158.        add 
  159.        headermargin
  160.     rmoveto
  161.         filename show                        % file name
  162.       grestore
  163.     } bind def
  164.  
  165. %
  166. % Function endpage: adds a sheet number to the page (footnote) and prints
  167. % the formatted page (physical impression). Activated at the end of each
  168. % source page (lines reached or FF character).
  169. /endpage
  170.    { /pagenum pagenum 1 add def
  171.      twinpage  sheetside 0 eq  and
  172.         { /sheetside 1 def }
  173.         { printpage }
  174.      ifelse
  175.    } bind def
  176.  
  177. % Function sheetnumber: prints the sheet number.
  178. /sheetnumber
  179.     { sheetnumberx sheetnumbery moveto
  180.       datefont setfont
  181.       sheet pnum cvs
  182.      dup stringwidth pop (0) stringwidth pop sub neg 0 rmoveto show
  183.       empty pnum copy pop
  184.     } bind def
  185.  
  186. % Function s: print a source line
  187. /s  { gsave
  188.         show
  189.       grestore
  190.       0 bodyfontsize neg rmoveto
  191.     } bind def
  192.